/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VIMS;


import java.sql.*;
import java.util.logging.Logger;

/**
 *
 * @author shyan
 */
public class Login {
        
        String host="jdbc:mysql://localhost:3306/vims";
        String username="root";
        String password="123";
        String UserID=null;
        String UserPW=null;
        
        Login()
        {
            UserID="";
            UserPW="";
        }
        
        Login(String InputID,String InputPW)
        {
            UserID=InputID;
            UserPW=InputPW;
            
            System.out.println(UserID+" "+UserPW);
        }
        
        
        
        
        public boolean check()
        {
              Connection con=null;
              String tempWord="";
              
            try
            {
                // load mysql driver
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection(host, username, password);
                
                Statement stmt = con.createStatement();
                String Query = "SELECT DES_DECRYPT(PW_PASSWORD) FROM PASSWORD WHERE PW_NUMBER IN (SELECT PW_NUMBER FROM EMPLOYEE WHERE EMP_USERNAME = '" +UserID + "')";
                ResultSet rset = stmt.executeQuery(Query);
                while (rset.next())
                {
                 tempWord = rset.getString(1);
                }              
                if(tempWord.equals(UserPW))
                    return(true);
                    
            }
            catch (SQLException e)
            {
                System.out.println("SQL Exception: "+ e.toString());
            }
            catch (ClassNotFoundException cE)
            {
                System.out.println("Class Not Found Exception: "+ cE.toString());
            }
            return(false);
        }
      
}
